<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

	<div id="id_panel">
	</div>
	<script th:inline="javascript">

	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
	    //自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
	    base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
		form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal
		/* 
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
		{
			id:'id_panel', // 页面容器ID
			dto: $.parseJSON(JSON.stringify([[${dto}]]))
		}
		);

		/*
		 * 监听表格中各个数字型输入框
		*/
		var domForm1 = $('#' + formObj.c.id_form);


		var t = formObj;

		// layui表单渲染，使控件生效
		layui.form.render();
		// 监听表单“保存”按钮
		layui.form.on('submit(formSubmit)', function(data){
			layer.confirm('是否取消，请确认。', { icon: 3 }, function() {
				var indexOfLoading = layer.load(1, {shade: [0.5,'#000000']});

				var commitPath = $('button[data-id="id_btn_save"]').attr('data-action');

				if(t.c.subGridConfig) {
					data.field['subData'] = JSON.stringify(t.getSubData());
				}
				if(t.c.dto.subGridConfig2) {
					data.field['subData'] = JSON.stringify(t.getSubData2());
				}
				$.post(commitPath, data.field, function(res){
					console.log('res',res);
					if (res.code == 0) {
						layer.msg('操作成功');
						var dto = res.data;
						setTimeout(function(){
							layer.close(indexOfLoading);
							if(dto == null || dto == undefined) {
								return;
							} else if(dto.code == 0) {
								return;
							} else if(dto.code == 1) {
								// 跳转编辑页
								window.location.href = dto.url;
							} else if(dto.code == 2) {

								if (window.parent) {
									// 关闭并刷新父列表
									window.parent.layer.close(parent.layer.getFrameIndex(window.name));
									window.parent.location.reload();
								} else {
									window.location.reload();
								}
							} else if(dto.code == 4) {
								window.top.closeTabActive();
							}	else if(dto.code == 5) {
								window.open(dto.url);
							}
						}, 1000);
					} else {
						//layer.close(indexOfLoading);
						layer.closeAll();
						layer.alert(res.msg);
					}
				});
				return false;
			}, function() {});



		});









	});

	</script>

</body>
</html>
